package com.kefu.call.service;

import com.kefu.call.mapper.CallGatewayMapper;
import com.kefu.common.service.AbstractKefuService;
import com.kefu.call.model.CallGateway;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.function.Function;

@Service
public class CallGatewayService extends AbstractKefuService<CallGateway> {

    @Resource
    private CallGatewayMapper callGatewayMapper;

    public String findByCompany(String tenantId) {
        return processCompany(tenantId, callGatewayMapper::findByCompany);
    }
    
    public String findIdByCompany(String tenantId) {
        return processCompany(tenantId, callGatewayMapper::findIdByCompany);
    }
    
    private String processCompany(String tenantId, Function<String, List<String>> function) {
        List<String> byCompany = function.apply(tenantId);
        // 将bycompany转换为逗号分割的字符串
        StringBuilder sb = new StringBuilder();
        for (String s : byCompany) {
            sb.append(s).append(",");
        }
        if (sb.length() > 0 && sb.charAt(sb.length() - 1) == ',') {
            sb.deleteCharAt(sb.length() - 1);
        }
        return sb.toString();
    }
}
